package com.ps.bicyclecharging.advice;

import com.ps.domain.ResultInfo;
import com.ps.enums.ErrorCode;
import com.ps.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description:controller异常通知类
 * @author:Lisa
 * @create:2019/07/08
 */
@ControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    private ResultInfo businessException(BusinessException e){

        //       根据code获取对应的提示语
        String msg = ErrorCode.statusOf(e.getCode()).getMsg();

        return new ResultInfo(msg, e.getCode(), null);
    }

}
